page.pageInit = function(){
  //初始化grid
  GirdCtr.gridInit();
  GirdCtr.buttonBind()
}

//grid控制器
var GirdCtr =  $.extend({},defaultGridConFig,{
   gridInit: function(){
	 var _this = this;
	//创建jqGrid组件
	_this.grid = $("#mainGrid").jqGrid({
		 			datatype: "json",
		 			url : contextPath+'/act/model/query.htm',//组件创建完成之后请求数据的url
					datatype : "json",//请求数据返回的类型。可选json,xml,txt
					colModel : [ //jqGrid每一列的配置信息。包括名字，索引，宽度,对齐方式.....
					             {label:"主键", name : "id",sortable:false,hidden:true,key:true},
					             {label:"模型ID", name : 'modelId',sortable:false,width : 220,align : "center"}, 
					             {label:"名称", name : 'name',sortable:false,width : 220,align : "center"}, 
					             {label:"业务名称", name : 'businessName',sortable:false,width : 220,align : "center"}, 
					             {label:"部署状态", name : 'status',sortable:false,width : 80,align : "center",edittype:"select",formatter:'select', editoptions:{value:systemDict.toString(systemDict.buildStatus)}}, 
					             {label:"组织", name : 'bapName',sortable:false,width : 200,align : "center"} ,
					             {label:"部门", name : 'baName',sortable:false,width : 200,align : "center"},
					             {label:"创建时间", name : 'createTime',sortable:false,width : 140,align : "center",formatter:DatFormatter}
					             ],
		            shrinkToFit:false,   
		            autoScroll: true, 
					rowNum : 10,//一页显示多少条
					rowList : [ 10, 20, 30 ],//可供用户选择一页显示多少条
					rownumWidth: 20, //设置显示序号的宽度，默认为25  
					pager : '#mainGridPager',//表格页脚的占位符(一般是div)的id
					sortname : 'createTime',//初始化的时候排序的字段
					sortorder : "asc",//排序方式,可选desc,asc
					mtype : "post",//向后台请求数据的ajax的类型。可选post,get
					width:page.window.grid.width,
					height:page.window.grid.height
					
				});
		/*创建jqGrid的操作按钮容器*/
		/*可以控制界面上增删改查的按钮是否显示*/
		$("#mainGrid").jqGrid('navGrid', '#mainGridPager', {edit:false,add:false,del:false,search:false,view:false,refresh:false});
	},
	buttonBind:function(){//控制按钮初始化
	  var _this = this;
	  $("#modelAddBtn").bind("click",function(){_this.event.doAdd(_this,this)});
	  $("#modelEditBtn").bind("click",function(){_this.event.doEdit(_this,this)});
	  $("#modelDeleteBtn").bind("click",function(){_this.event.doDelete(_this,this)});
	  $("#modelDetailBtn").bind("click",function(){_this.event.doDetail(_this,this)});
	  $("#modelSettingBtn").bind("click",function(){_this.event.doSetting(_this,this)});
	  $("#modelNodeBtn").bind("click",function(){_this.event.doNode(_this,this)});
	  $("#modelPicBtn").bind("click",function(){_this.event.doPic(_this,this)});
	  $("#modelBuildBtn").bind("click",function(){_this.event.doBuildProcess(_this,this)});
	  $("#modelUpBtn").bind("click",function(){_this.event.doUp(_this,this)});
	}, 
	event:{//事件
	  doAdd:function(_this,btn){
		  var menuId = $(btn).attr("menuId");
			  var params = {menuId:menuId}
			  showWindow("添加模型",contextPath+"/act/model/addView.htm",params,function(){
				  GirdCtr.reLoad();
			  });
	  },
	  doEdit:function(_this,btn){//修改
		  var menuId = $(btn).attr("menuId");
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			  var params = {menuId:menuId,id:node.id}
			  showWindow("修改模型",contextPath+"/act/model/editView.htm",params,function(){
				  GirdCtr.reLoad();
			  });
		  }else{
			  layer.msg("选择需要修改的数据");
		  }
	  },
	  doDetail:function(_this,btn){//修改
		  var menuId = $(btn).attr("menuId");
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			  var params = {menuId:menuId,id:node.id}
			  showWindow("查看",contextPath+"/act/model/detailView.htm",params,function(){
				  
			  },true);
		  }else{
			  layer.msg("选择需要查看的数据");
		  }
	  },
	  doSetting:function(_this,btn){//修改
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			  var params = {}
			  showIframeWindow("流程设计",contextPath+"/process/modeler.html?modelId="+node.modelId,params,function(){
				  
			  },true);
		  }else{
			  layer.msg("选择需要查看的数据");
		  }
	  },
	  doNode:function(_this,btn){//节点设置
		  var menuId = $(btn).attr("menuId");
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			  var params = {menuId:menuId,id:node.modelId}
			  showWindow("节点设置",contextPath+"/act/model/nodeView.htm",params,function(){
				  
			  },true);
		  }else{
			  layer.msg("选择需要查看的数据");
		  }
	  },
	  doPic:function(_this,btn){//流程图
		  var menuId = $(btn).attr("menuId");
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			  var params = {menuId:menuId,modelId:node.modelId}
			 var url = contextPath+"/act/model/picView.htm?modelId="+node.modelId;
			  var html ="<img src ='"+url+"'/>";
		        //弹框层
		        layer.open({
		            type: 1,
		            area: ['70%', '70%'], //宽高
		            content: html,
		            title:['查看流程图',true],
		            shadeClose: true, //开启遮罩关闭
		        });
		  }else{
			  layer.msg("选择需要查看的数据");
		  }
	  },
	  doBuildProcess:function(_this,btn){//部署
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			 var laIndex = layer.confirm('确定要部署该数据吗？', {
				  btn: ['确定','取消'] //按钮
				}, function(){
					_this.event.gridDoBuild(node.modelId,_this);
					layer.close(laIndex);
				});
		  }else{
			  layer.msg("请选择部署的数据.");
		  }
	  },
	  doUp:function(_this,btn){//升级
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			 var laIndex = layer.confirm('确定要升级该数据吗？', {
				  btn: ['确定','取消'] //按钮
				}, function(){
					_this.event.gridDoBuild(node.modelId,_this);
					layer.close(laIndex);
				});
		  }else{
			  layer.msg("请选择部署的数据.");
		  }
	  },
	  doDelete:function(_this,btn){//删除
		  var id = _this.grid.jqGrid('getGridParam','selrow');
		  if(id){
			 var laIndex = layer.confirm('确定要删除该数据吗？', {
				  btn: ['确定','取消'] //按钮
				}, function(){
					_this.event.gridDoDelete(id,_this);
					layer.close(laIndex);
				});
		  }else{
			  layer.msg("请选择删除的数据.");
		  }
	  },gridDoDelete:function(id,_this){
		  $.dataPost(contextPath+'/act/model/delete.htm',{id:id},function(result){
			  if(result.success){
				  GirdCtr.reLoad();
			  }else{
				  layer.msg(result.msg); 
			  }
		  });
	  },gridDoBuild:function(modelId,_this){
		  $.dataPost(contextPath+'/act/model/build.htm',{modelId:modelId},function(result){
			  if(result.success){
				  GirdCtr.reLoad();
			  }else{
				  layer.msg(result.msg); 
			  }
		  });
	  }
	}
});

